package net.ojbk.jiaofu.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.ojbk.jiaofu.service.TaskService;

/**
 * Servlet implementation class TaskServlet
 */
@WebServlet("/task.jsp")
public class TaskServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TaskServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 控制 是否正确访问
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		// 前奏 ↑ ↑ ↑ ↑ ↑
		
		// 获取 taskId
		String taskId = request.getParameter("taskId");
		
		// 获取 taskType
		int taskType = TaskService.getTaskType(taskId);
		
		// 进行转向 forwor
		switch (taskType) {
		case 1: // image
			request.getRequestDispatcher("collectImage.jsp").forward(request, response);return ;
		case 2: // Zip
			request.getRequestDispatcher("collectZip.jsp").forward(request, response);return ;
		case 3: // Excel
			request.getRequestDispatcher("collectExcel.jsp").forward(request, response);return ;
		case 0: // 假的
			request.getRequestDispatcher("home.jsp").forward(request, response);return ;
		}
		request.getRequestDispatcher("home.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
